package com.gitee.qdbp.general.common.web.controller.editor;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baidu.ueditor.ActionEnter;
import com.gitee.qdbp.base.annotation.OperateRecord;
import com.gitee.qdbp.base.enums.OperateType;
import com.gitee.qdbp.general.common.api.files.service.IWebFileService;
import com.gitee.qdbp.general.common.web.controller.files.UeditorUploader;

/**
 * UEditor文件上传下载控制器
 *
 * @author zhaohuihua
 * @version 150325
 */
@Controller
@RequestMapping("actions/common/ueditor")
public class UeditorController {

    @Autowired
    private IWebFileService webFileService;

    private UeditorUploader uploader;

    @PostConstruct
    protected void init() {
        this.uploader = new UeditorUploader(webFileService);
    }

    @RequestMapping("exec")
    @OperateRecord(value = "UEditor", type = OperateType.UPDATE)
    public void exec(HttpServletRequest request, HttpServletResponse response) throws Exception {

        request.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Type", "text/html");

        String rootPath = request.getServletContext().getRealPath("/");
        response.getWriter().write(new ActionEnter(uploader, request, rootPath).exec());
    }
}
